package cn.jhc.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.bean.Account;
import cn.jhc.bean.User;
import cn.jhc.dao.AccountDAO;
import cn.jhc.dao.DaoType;
import cn.jhc.factory.DAOFactory;

/**
 * Servlet implementation class CartBalanceServlet
 */
@WebServlet("/balance.do")
public class CartBalanceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CartBalanceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String prices = request.getParameter("balan");
		User user = (User) request.getSession().getAttribute("currentUser");
		AccountDAO dao = (AccountDAO)DAOFactory.getDao(DaoType.ACCOUNT);
		List<Account> accounts =  dao.getAll(user.getUserId());
		request.getSession().setAttribute("accountAll", accounts);
		request.getSession().setAttribute("prices", prices);
		request.getRequestDispatcher("/WEB-INF/jsp/balance.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
